﻿using System.Collections.Generic;
using System.Threading.Tasks;
using ESoft.DataAccess.Models;

namespace ESoft.DataAccess
{
    /// <summary>
    /// SQl查询服务
    /// </summary>
    public interface ISqlRepositry
    {
        /// <summary>
        /// 按SQL获取实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        List<T> FindBySql<T>(string query, params object[] parameters) where T : class, new();
        
        /// <summary>
        /// 按SQL获取实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<List<T>> FindBySqlAsync<T>(string query, params object[] parameters) where T : class, new();

        /// <summary>
        /// 分页获取SQL
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rawSql"></param>
        /// <param name="pageInput"></param>
        /// <param name="orderBy"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        PageResult<T> FindPageBySql<T>(string rawSql, PageInput pageInput, string orderBy, params object[] parameters) where T : class, new();
        
        /// <summary>
        /// 分页获取SQL
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rawSql"></param>
        /// <param name="pageInput"></param>
        /// <param name="orderBy"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<PageResult<T>> FindPageBySqlAsync<T>(string rawSql, PageInput pageInput, string orderBy, params object[] parameters) where T : class, new();

        /// <summary>
        /// 获取首值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rawSql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        T ExecuteScalar<T>(string rawSql, params object[] parameters);
        
        /// <summary>
        /// 获取首值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rawSql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<T> ExecuteScalarAsync<T>(string rawSql, params object[] parameters);
    }
}
